package com.heima.wemedia.controller;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.wemedia.dto.WnMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import com.jlefebure.spring.boot.minio.MinioException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-06-03
 */
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 文件上传
     */
    @PostMapping("/upload_picture")
    public ResponseResult muitipartFile(MultipartFile multipartFile) throws Exception {

     return  wmMaterialService.uploadPicture(multipartFile);
    }


    /**
     * 自媒体图文素材分页查询
     */
    @PostMapping("/list")
    public ResponseResult pager(@RequestBody WnMaterialDto dto){

        return wmMaterialService.pager(dto);
    }

    /**
     * 收藏素材
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id){
        return  wmMaterialService.collect(id);
    }
    /**
     * 删除素材
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable Integer id) throws MinioException {
        return wmMaterialService.delete(id);
    }
}
